package com.situ.feemanagement.controller;

import com.situ.feemanagement.pojo.Department;
import com.situ.feemanagement.pojo.query.DepartmentQuery;
import com.situ.feemanagement.service.IDepartmentService;
import com.situ.feemanagement.util.PageResult;
import com.situ.feemanagement.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    @RequestMapping("/selectAll")
    public List<Department> selectAll() {
        return departmentService.selectAll();
    }

    @RequestMapping("/selectByPage")
    public PageResult<Department> selectByPage(DepartmentQuery departmentQuery) {
        return departmentService.selectByPage(departmentQuery);
    }

    @RequestMapping("/deleteById")
    public Result deleteById(String id) {
        departmentService.deleteById(Integer.parseInt(id));
        return Result.ok("删除成功");
    }

    @RequestMapping("/deleteAll")
    public Result deleteAll(String[] ids) {
        departmentService.deleteByAll(ids);
        return Result.ok("删除成功");
    }

    @RequestMapping("/add")
    public Result add(Department department) {
        departmentService.add(department);
        return Result.ok("添加成功");
    }

    @RequestMapping("/selectById")
    public Result selectById(String id) {
        Department department = departmentService.selectById(Integer.parseInt(id));
        return Result.ok(department);
    }

    @RequestMapping("/update")
    public Result update(Department department) {
        departmentService.update(department);
        return Result.ok("更新成功");
    }
}
